package cn.kuporo.seckill.stock.controller;

import cn.kuporo.seckill.common.model.response.Response;
import cn.kuporo.seckill.stock.application.model.command.SeckillStockBucketWrapperCommand;
import cn.kuporo.seckill.stock.application.model.dto.SeckillStockBucketDTO;
import cn.kuporo.seckill.stock.application.service.SeckillStockBucketService;
import com.alibaba.nacos.api.model.v2.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: kuporo
 * @since: 2025/8/2
 * @description: 分桶库存
 */

@RestController
@RequestMapping(value = "/stock/bucket")
@RequiredArgsConstructor
public class SeckillStockBucketController {
    
    private final SeckillStockBucketService seckillStockBucketService;

    /**
     * 库存分桶
     */
    @PostMapping( "/arrangeStockBuckets")
    public Response<?> arrangeStockBuckets(@RequestBody SeckillStockBucketWrapperCommand seckillStockCommond){
        Long userId = 1L;
        seckillStockBucketService.arrangeStockBuckets(userId, seckillStockCommond);
        return Response.success();
    }

    /**
     * 获取库存分桶数据
     */
    @GetMapping ("/getTotalStockBuckets")
    public Response<SeckillStockBucketDTO> getTotalStockBuckets(Long goodsId, Long version){
        return Response.success(seckillStockBucketService.getTotalStockBuckets(goodsId, version));
    }
}
